from django.forms import model_to_dict

from libs.common import success
from libs.form import RawJsonForm
from trade.models.goods import Goods


def goods_list(request):
    form = RawJsonForm(request.body)
    p = form.get_page()
    sets = Goods.objects.all()[p.start:p.end].values()
    rd = {
        'data': list(sets),
        'page': p.page,
        'size': p.size
    }
    return success(**rd)


def goods_detail(request):
    form = RawJsonForm(request.body)
    goods_id = form.get('id')
    goods = Goods.objects.filter(id=goods_id).get()
    return success(model_to_dict(goods))


def add_goods(request):
    return


def update_goods(request):
    return


def del_goods(request):
    return
